package com.example.actionsignin.dialog;

import android.app.Dialog;
import android.app.DialogFragment;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.example.actionsignin.R;
import com.example.actionsignin.mvp.presenter.IManagerSignTypeListener;

/**
 * Created by 旭 on 2017/10/6/006.
 */

public class SignTypeDialogFragment extends DialogFragment implements View.OnClickListener{

    private View view;

    private IManagerSignTypeListener listener = null;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(STYLE_NO_TITLE);

        Window window = this.getDialog().getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.windowAnimations = R.style.BottomDialogAnimation;
        window.setAttributes(layoutParams);

        view = inflater.inflate(R.layout.fragment_dialog_sign_type,container,false);

        initView();

        return view;
    }

    private void initView() {
        view.findViewById(R.id.fragment_dialog_sign_type_1).setOnClickListener(this);
        view.findViewById(R.id.fragment_dialog_sign_type_2).setOnClickListener(this);
        view.findViewById(R.id.fragment_dialog_sign_type_3).setOnClickListener(this);

        listener = (IManagerSignTypeListener) getActivity();
    }

    @Override
    public void onStart() {
        super.onStart();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        getDialog().getWindow().setLayout((displayMetrics.widthPixels),getDialog().getWindow().getAttributes().height);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.fragment_dialog_sign_type_1:
                break;
            case R.id.fragment_dialog_sign_type_2:
                listener.doSomeThing(2);
                dismiss();
                break;
            case R.id.fragment_dialog_sign_type_3:
                dismiss();
                break;
        }
    }
}
